<?php
add_filter ('the_content', 'prod_registration', 0);
function prod_registration($content) {	
	
	if ( is_page('new-user') ) {
		
		//es: http://192.168.1.190/cricco/css/new-user/?login_name=c.ricco&user_pass=asd&user_email=info@syriusweb.com&first_name=Carmine&last_name=Ricco&remote=1
		
		$userdata = array();		
		
		$login_name = $_GET['login_name'];
		$user_pass = $_GET['user_pass'];
		$user_email = $_GET['user_email'];
		$first_name = $_GET['first_name'];
		$last_name = $_GET['last_name'];
		$remote = $_GET['remote'];
		
		$userdata = array(
		    'user_login'	=>  $login_name,
			'user_pass'		=>  $user_pass,
			'user_email'	=>  $user_email,
			'first_name'	=>  $first_name,
			'last_name'		=>  $last_name,
			'role'			=>  'user',
		    'user_url'  	=> 	''
		);
		
		$user_id = wp_insert_user( $userdata );
		
		//On success
		if( !is_wp_error($user_id) ) {
			//echo "User created: ". $user_id;
			
			update_user_meta( $user_id, 'remote', $remote);			
			
			wp_send_json($user_id);
		} else {
			//echo "An error occurred";
			wp_send_json(false);		
		}
					
	}	
	 
	return $content.$cont;
	
}
?>

